package com._520it.crm.service.impl;

import com._520it.crm.domain.RenewalInsurance;
import com._520it.crm.mapper.OrderBillMapper;
import com._520it.crm.mapper.RenewalInsuranceMapper;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.QueryObject;
import com._520it.crm.service.IRenewalInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by 呆 on 2017/10/3.
 */
@Service
public class RenewalInsuranceServiceImpl implements IRenewalInsuranceService {
    @Autowired
    private RenewalInsuranceMapper renewalInsuranceMapper;
    @Autowired
    private OrderBillMapper orderBillMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return renewalInsuranceMapper.deleteByPrimaryKey(id);
    }

    /**
     * 保存续保申请明细是将保单的状态修改40 为续保申请单;
     * @param renewalInsurance 续保明细对象
     * @return
     */
    @Override
    public int insert(RenewalInsurance renewalInsurance) {
        orderBillMapper.changeState(renewalInsurance.getOrderBillId());
        return renewalInsuranceMapper.insert(renewalInsurance);
    }

    @Override
    public RenewalInsurance selectByPrimaryKey(Long id) {
        return renewalInsuranceMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<RenewalInsurance> selectAll() {
        return renewalInsuranceMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(RenewalInsurance renewalInsurance) {
        return renewalInsuranceMapper.updateByPrimaryKey(renewalInsurance);
    }

    @Override
    public PageResult query(QueryObject qo) {
        Integer totalCount = renewalInsuranceMapper.queryforCount(qo);
        if (totalCount==0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<RenewalInsurance> data = renewalInsuranceMapper.queryforList(qo);
        return new PageResult(totalCount,data);
    }


}
